#include "RenderMesh.h"

#include "WriteInMesh.h"

CRenderMesh::CRenderMesh()
{
    WriteInMesh=new CWriteInMesh();
}


void CRenderMesh::SetMeshData(const TVector<SVertex> &InVertice,const TVector<uint32_t>& InIndices)
{
    std::lock_guard<std::mutex> Lock(WriteInMesh->Mutex);
    WriteInMesh-> Vertice = InVertice;
    WriteInMesh->Indices = InIndices;
    WriteInMesh->bDirty = true;
}


// void CRenderMesh::MakeSureNotDirty()
// {
//     if(MeshData.Empty())
//     {
//         return;
//     }

//     if(!VulkanMesh)
//     {
//         VulkanMesh=std::make_shared<CVulkanMesh>();
//     }

//     std::lock_guard<std::mutex> Lock(MeshDataMutex);
//     VulkanMesh->VertexCount=MeshData.Num();

//     //create buffer
//     if (!VulkanMesh->VertexBuffer)
//     {
//         VulkanMesh->VertexBuffer=std::make_shared<CVulkanVertexBuffer>(VulkanMesh->VertexCount * sizeof(SVertex));
//     }

//     //写入顶点数据
//     VulkanMesh->VertexBuffer->WriteData(MeshData.Data(), VulkanMesh->VertexCount * sizeof(SVertex));

//     //clear data
//     MeshData.Clear();

//     VulkanMesh->IndexCount=Indices.Num();
//     if(VulkanMesh->IndexCount>0)
//     {
//         //create index buffer
//         if (!VulkanMesh->IndexBuffer)
//         {
//             VulkanMesh->IndexBuffer=std::make_shared<CVulkanIndexBuffer>(VulkanMesh->IndexCount * sizeof(uint32_t));   
//         }

//         //写入索引数据
//         VulkanMesh->IndexBuffer->WriteData(Indices.Data(), VulkanMesh->IndexCount * sizeof(uint32_t));

//         //clear data
//         Indices.Clear();
//     }
// }

// void CRenderMesh::RecordDrawCommands(vk::CommandBuffer InCmdBuffer)
// {
//     assert(VulkanMesh);
//     VulkanMesh->RecordDrawCommands(InCmdBuffer);
// }
